#pragma once

class M2VideoLoadTask;
class M2Info;

class M2BatchRender
{
private:
	static D3DVERTEXELEMENT9 ElemDecl[];
	std::vector<Texture*> mTextures;
	M2VideoLoadTask* mLoadTask;
	M2InstanceLoader mInstanceLoader;
	IDirect3DVertexDeclaration9* mDecl;
	M2Info& mModelInfo;
	IDirect3DVertexBuffer9* mInstanceDataBuffer;
	IDirect3DVertexBuffer9* mVertexBuffer;
	IDirect3DIndexBuffer9* mIndexBuffer;
	ui32 mNumInstances;
	std::string mModelName;
public:
	M2BatchRender(const std::string& modelName);

	void setVertices(IDirect3DVertexBuffer9* vertices) {
		mVertexBuffer = vertices;
	}
	
	void setIndices(IDirect3DIndexBuffer9* indices) {
		mIndexBuffer = indices;
	}

	void addTexture(Texture* texture) {
		mTextures.push_back(texture);
	}

	ui32 addInstance(float x, float y, float z, float scale, float rx, float ry, float rz);
	bool removeInstance(ui32 id);
	void changeInstancePosition(ui32 id, const Vertex3F& position);

	void renderInstance();

	void setNumInstances(ui32 instances) { mNumInstances = instances; }

	IDirect3DVertexBuffer9* getInstanceBuffer() { return mInstanceDataBuffer; }
	IDirect3DVertexBuffer9** getInstanceBufferPtr() { return &mInstanceDataBuffer; }
};